package nuc.edu.tlias.service.impl;

import nuc.edu.tlias.mapper.ClazzMapper;
import nuc.edu.tlias.mapper.EmpMapper;
import nuc.edu.tlias.mapper.StudentMapper;
import nuc.edu.tlias.pojo.ClazzCountOption;
import nuc.edu.tlias.pojo.JobOption;
import nuc.edu.tlias.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Map;
import java.util.Objects;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    EmpMapper empMapper;
    @Autowired
    StudentMapper studentMapper;
    @Autowired
    ClazzMapper clazzMapper;

    @Override
    public JobOption getEmpJobData() {

        List<Map<String, Object>> list = empMapper.EmpJobData();

        List<Object> jobList = list.stream().map(dataMap -> dataMap.get("pos")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("num")).toList();

        return new JobOption(jobList, dataList);
    }

    @Override
    public List<Map<String, Object>> getEmpGenderData() {
        List<Map<String, Object>> list = empMapper.getEmpGenderData();
        return list;
    }

    @Override
    public List<Map<String, Object>> getStudentDegreeData() {
        List<Map<String, Object>> list = studentMapper.getStudentDegreeData();
        return list;
    }

    @Override
    public ClazzCountOption getStudentCount() {
        List<Map<String, Object>> countList = studentMapper.getStudentCount();
        if (!CollectionUtils.isEmpty(countList)) {
            List<Object> clazzList = countList.stream().map(map -> {
                return map.get("cname");
            }).toList();

            List<Object> dataList = countList.stream().map(map -> {
                return map.get("scount");
            }).toList();

            return new ClazzCountOption(clazzList, dataList);
        }
        return null;

    }

}
